package com.food.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.food.dao.service.ApplicationService;
import com.food.dao.service.CollectService;
import com.food.dao.service.CourseService;
import com.food.dao.service.RecipeService;
import com.food.model.Application;
import com.food.model.Collect;
import com.food.model.Course;
import com.food.model.Member;
import com.food.model.Recipe;

/**
 * Servlet implementation class MyCollect
 */
@WebServlet("/member/MyCollect")
public class MyCollect extends HttpServlet {
	private static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		CollectService service = new CollectService();
		RecipeService rservice = new RecipeService();
		HttpSession session = request.getSession();
		Member member = (Member)session.getAttribute("user");
		Collect c = new Collect();
		c.setMbid(member.getMbid());
		List<Collect> listCollect = service.findCollectByMb(c);
		List<Recipe> coll = new ArrayList<Recipe>();
		for(Collect collect:listCollect){
			Recipe recipe = new Recipe();
			recipe.setRid(collect.getRid());
			recipe = rservice.findRecipeById(recipe);
			coll.add(recipe);
			
		}
		request.setAttribute("mbCollect", coll);
		RequestDispatcher rd = request
				.getRequestDispatcher("/member/mycollect.jsp");
		rd.forward(request, response);
		return;
	}

}
